package com.itheima.thread.Demo5;

public class SellTicket implements Runnable {
    private int tickets = 1000;
    @Override
    public void run() {
        while (true) {
            synchronized ("1") {
                if(tickets <= 0){
                    break;
                }else{
                    tickets--;
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"正在买票,剩余票数有"+tickets+"张");
                }
            }
        }
    }
}
